'''
@Descripttion: 颜色分类
@version: v1.0
@encoding: utf-8
@Author: qiurongcan
Date: 2025-05-15 11:43:25
LastEditTime: 2025-05-15 11:52:27
'''

class Solution():
    def sortColors(self, nums: list[int]) -> None:

        if len(nums) < 2:
            return
        
        last = {
            0 : -1,
            1 : -1,
            2 : -1,
        }
        for num in nums:
            if num == 0:
                last[0] += 1
                last[1] += 1
                last[2] += 1
                nums[last[2]] = 2
                nums[last[1]] = 1
                nums[last[0]] = 0

            elif num == 1:
                last[1] += 1
                last[2] += 1
                nums[last[2]] = 2
                nums[last[1]] = 1

            else:
                last[2] += 1
                nums[last[2]] = 2

if __name__ == "__main__":

    nums = [2,0,2,1,1,0]
    sol = Solution()
    sol.sortColors(nums)

    print(nums)